import { ReportDTO } from './../dto/report';
import { Report } from '../entity/report';
import { Provide } from '@midwayjs/decorator';
import BaseServices from '../core/baseServices';
import { getModelForClass } from '@typegoose/typegoose';

@Provide()
export class ReportService extends BaseServices {
  /**
   * 保存 record 并且返回id
   * @param param0
   * @returns
   */
  async saveReport({ events, date, request }: ReportDTO) {
    const ReportModel = getModelForClass(Report);
    const report = new ReportModel();
    report.events = events;
    report.date = date;
    report.request = request;
    const reportInfo = await report.save();
    return reportInfo._id;
  }

  /**
   * 获取记录列表
   * @returns
   */
  async getReportList() {
    const ReportModel = getModelForClass(Report);
    return ReportModel.find({}, { events: 0, request:0, _v:0 });
  }

  /**
   * 获取记录详情
   * @returns
   */
  async getReportDetail(eventId: string) {
    const ReportModel = getModelForClass(Report);
    return ReportModel.findById(eventId);
  }
}
